<?php
/**
 * Role Model
 * 
 * @author Dac Diep Vuong
 * @package acl.model
 */ 
class Role_model extends Model
{
    private $table = 'role';
    
    public function add($data) {
        if(!$data) return false;
        $result = $this->db->insert($this->table, $data);
        return $result;
    }
    
    public function update($data, $id = 0) {
        if(!$data || !$id) return false;
        $result = $this->db->update($this->table, $data, array('role_id' => $id));
        return $result;
    }
    
    public function active($id = 0) {
        if(!$id) return false;
        $result = $this->db->query('UPDATE `role` SET `active` = 2 - ( 1 + `active` ) WHERE `role_id` = '. $id);
        return $result;
    }
    
    /**
     * Delete role
     * 
     * @desc Xóa nhóm quyền
     * @param Int $id
     * @return Int | False
     */
    public function del($id = 0) {
        if(!$id) return false;
        $result = $this->db->delete($this->table, "role_id = ". $id);
        return $result;
    }
    
    /**
     * Get list role
     * 
     * @desc Danh sánh nhóm quyền
     * @return Array | False
     */
    public function getList() {  
        $result = $this->db->get($this->table);
        return $result->result_object();
    }
    
    public function getRoleInfo($id = 0) {
        if(!$id) return false;
        $result = $this->db->getwhere($this->table, "role_id = ". $id);
        return $result->row();
    }
}  
?>
